<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
        Java-framework-MyBatis-1 - rulerLwx Blog
      </title>
        <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    
    <meta name="theme-color" content="#000000" />
    
    <meta http-equiv="window-target" content="_top" />
    
    
    <meta name="description" content="Mybatis架构 github https://github.com/mybatis/mybatis-3 英文文档 http://www.mybatis.org/mybatis-3/ 1、mybatis配置 SqlMapConfig.xml，此文件作为mybatis的全局配置文件，配置了myb" />
    <meta name="generator" content="Hugo 0.73.0 with theme pure" />
    <title>Java-framework-MyBatis-1 - rulerLwx Blog</title>
    
    
    <link rel="stylesheet" href="https://rulerLwx.gitee.io/css/style.min.c4bc7071f132c964c2116bca53b392933f377e5ca7b7051ed245187c621a2d3e.css">
    
    <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/9.15.10/styles/github.min.css" async>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css" async>
    <meta property="og:title" content="Java-framework-MyBatis-1" />
<meta property="og:description" content="Mybatis架构 github https://github.com/mybatis/mybatis-3 英文文档 http://www.mybatis.org/mybatis-3/ 1、mybatis配置 SqlMapConfig.xml，此文件作为mybatis的全局配置文件，配置了myb" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://rulerLwx.gitee.io/2020/07/java-framework-mybatis-1/" />
<meta property="article:published_time" content="2020-07-01T18:58:47+08:00" />
<meta property="article:modified_time" content="2020-07-01T18:58:47+08:00" />
<meta itemprop="name" content="Java-framework-MyBatis-1">
<meta itemprop="description" content="Mybatis架构 github https://github.com/mybatis/mybatis-3 英文文档 http://www.mybatis.org/mybatis-3/ 1、mybatis配置 SqlMapConfig.xml，此文件作为mybatis的全局配置文件，配置了myb">
<meta itemprop="datePublished" content="2020-07-01T18:58:47&#43;08:00" />
<meta itemprop="dateModified" content="2020-07-01T18:58:47&#43;08:00" />
<meta itemprop="wordCount" content="5748">



<meta itemprop="keywords" content="" /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Java-framework-MyBatis-1"/>
<meta name="twitter:description" content="Mybatis架构 github https://github.com/mybatis/mybatis-3 英文文档 http://www.mybatis.org/mybatis-3/ 1、mybatis配置 SqlMapConfig.xml，此文件作为mybatis的全局配置文件，配置了myb"/>

    <!--[if lte IE 9]>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
      <![endif]-->

    <!--[if lt IE 9]>
        <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
      <![endif]-->
  </head>

  
  

  <body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage"><header class="header" itemscope itemtype="http://schema.org/WPHeader">
    <div class="slimContent">
      <div class="navbar-header">
        <div class="profile-block text-center">
          <a id="avatar" href="https://gitee.com/rulerLwx" target="_blank">
            <img class="img-circle img-rotate" src="https://rulerLwx.gitee.io/avatar.png" width="200" height="200">
          </a>
          <h2 id="name" class="hidden-xs hidden-sm">rulerLwx</h2>
          <h3 id="title" class="hidden-xs hidden-sm hidden-md">thinking...</h3>
          <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i>Guangzhou, China</small>
        </div><div class="search" id="search-form-wrap">
    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i
                        class="icon icon-search"></i></button>
            </span>
        </div>
        <div class="ins-search">
            <div class="ins-search-mask"></div>
            <div class="ins-search-container">
                <div class="ins-input-wrapper">
                    <input type="text" class="ins-search-input" placeholder="Type something..."
                        x-webkit-speech />
                    <button type="button" class="close ins-close ins-selectable" data-dismiss="modal"
                        aria-label="Close"><span aria-hidden="true">×</span></button>
                </div>
                <div class="ins-section-wrapper">
                    <div class="ins-section-container"></div>
                </div>
            </div>
        </div>
    </form>
</div>
        <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
        <ul class="nav navbar-nav main-nav">
            <li class="menu-item menu-item-home">
                <a href="/">
                    <i class="icon icon-home-fill"></i>
                  <span class="menu-title">Home</span>
                </a>
            </li>
            <li class="menu-item menu-item-archives">
                <a href="/posts/">
                    <i class="icon icon-archives-fill"></i>
                  <span class="menu-title">Archives</span>
                </a>
            </li>
            <li class="menu-item menu-item-categories">
                <a href="/categories/">
                    <i class="icon icon-folder"></i>
                  <span class="menu-title">Categories</span>
                </a>
            </li>
            <li class="menu-item menu-item-tags">
                <a href="/tags/">
                    <i class="icon icon-tags"></i>
                  <span class="menu-title">Tags</span>
                </a>
            </li>
            <li class="menu-item menu-item-about">
                <a href="/about/">
                    <i class="icon icon-cup-fill"></i>
                  <span class="menu-title">About</span>
                </a>
            </li>
        </ul>
      </nav>
    </div>
  </header>

<aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">enjoy~
            </div>
        </div>
    </div>
</div>

      <div class="widget">
    <h3 class="widget-title"> Categories</h3>
    <div class="widget-body">
        <ul class="category-list">
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-framework/" class="category-list-link">java-framework</a><span class="category-list-count">38</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-front-end/" class="category-list-link">java-front-end</a><span class="category-list-count">11</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-se/" class="category-list-link">java-se</a><span class="category-list-count">21</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-senior/" class="category-list-link">java-senior</a><span class="category-list-count">4</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/linux/" class="category-list-link">linux</a><span class="category-list-count">13</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/tools/" class="category-list-link">tools</a><span class="category-list-count">1</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/%E6%8A%80%E6%9C%AF%E6%9D%82%E7%83%A9/" class="category-list-link">技术杂烩</a><span class="category-list-count">4</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" class="category-list-link">数据库</a><span class="category-list-count">15</span></li>
        </ul>
    </div>
</div>
      <div class="widget">
    <h3 class="widget-title"> Tags</h3>
    <div class="widget-body">
        <ul class="tag-list">
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/jvm/" class="tag-list-link">jvm</a><span
                    class="tag-list-count">1</span></li>
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" class="tag-list-link">多线程</a><span
                    class="tag-list-count">2</span></li>
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" class="tag-list-link">网络编程</a><span
                    class="tag-list-count">3</span></li>
            
        </ul>

    </div>
</div>
      
<div class="widget">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget-body">
        <ul class="recent-post-list list-unstyled no-thumbnail">
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E8%87%AA%E5%B7%B1%E5%8A%A8%E6%89%8B%E4%B8%80%E6%89%B9%E9%87%8F%E7%A7%BB%E5%8A%A8%E9%87%8D%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6/" class="title">自己动手（一）——批量移动、重命名文件</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-27 17:50:02 &#43;0800 CST" itemprop="datePublished">2020-07-27</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E5%85%B3%E4%BA%8Einteger%E7%9A%84-128~127%E7%BC%93%E5%AD%98/" class="title">关于Integer的 -128~127缓存</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-11 16:56:21 &#43;0800 CST" itemprop="datePublished">2020-07-11</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/" class="title">跨域问题</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-08 22:41:12 &#43;0800 CST" itemprop="datePublished">2020-07-08</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" class="title">个人博客搭建</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-05 18:58:47 &#43;0800 CST" itemprop="datePublished">2020-07-05</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/centos/" class="title">CentOS-</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-01 18:58:47 &#43;0800 CST" itemprop="datePublished">2020-07-01</time>
                    </p>
                </div>
            </li>
        </ul>
    </div>
</div>
  </div>
</aside>

    
    
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <h4 class="toc-title">Catalogue</h4>
    <nav id="toc" class="js-toc toc">

    </nav>
  </div>
</aside>
<main class="main" role="main"><div class="content">
  <article id="-" class="article article-type-" itemscope
    itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      <h1 itemprop="name">
  <a
    class="article-title"
    href="/2020/07/java-framework-mybatis-1/"
    >Java-framework-MyBatis-1</a
  >
</h1>

      <div class="article-meta">
        
<span class="article-date">
  <i class="icon icon-calendar-check"></i>&nbsp;
<a href="https://rulerLwx.gitee.io/2020/07/java-framework-mybatis-1/" class="article-date">
  <time datetime="2020-07-01 18:58:47 &#43;0800 CST" itemprop="datePublished">2020-07-01</time>
</a>
</span>
<span class="article-category">
  <i class="icon icon-folder"></i>&nbsp;
  <a class="article-category-link" href="/categories/java-framework/"> Java-framework </a>
</span>

        <span class="post-comment"><i class="icon icon-comment"></i>&nbsp;<a href="/2020/07/java-framework-mybatis-1/#comments"
            class="article-comment-link">Comments</a></span>
		<span class="post-wordcount hidden-xs" itemprop="wordCount">Word Count: 5748words</span>
		<span class="post-readcount hidden-xs" itemprop="timeRequired">Read Count: 12minutes </span>
      </div>
    </div>
    <div class="article-entry marked-body js-toc-content" itemprop="articleBody">
      <h1 id="mybatis架构">Mybatis架构</h1>
<p>github <a href="https://github.com/mybatis/mybatis-3">https://github.com/mybatis/mybatis-3</a></p>
<p>英文文档 <a href="http://www.mybatis.org/mybatis-3/">http://www.mybatis.org/mybatis-3/</a></p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080338.png" alt=""></p>
<p>1、mybatis配置</p>
<p>SqlMapConfig.xml，此文件作为mybatis的全局配置文件，配置了mybatis的运行环境等信息。</p>
<p>mapper.xml文件即sql映射文件，文件中配置了操作数据库的sql语句。此文件需要在SqlMapConfig.xml中加载。</p>
<p>2、通过mybatis环境等配置信息构造SqlSessionFactory即会话工厂</p>
<p>3、由会话工厂创建sqlSession即会话，操作数据库需要通过sqlSession进行。</p>
<p>4、mybatis底层自定义了Executor执行器接口操作数据库，Executor接口有两个实现，一个是基本执行器、一个是缓存执行器。</p>
<p>5、Mapped Statement也是mybatis一个底层封装对象，它包装了mybatis配置信息及sql映射信息等。mapper.xml文件中一个sql对应一个Mapped Statement对象，sql的id即是Mapped statement的id。</p>
<p>6、Mapped Statement对sql执行输入参数进行定义，包括HashMap、基本类型、pojo，Executor通过Mapped Statement在执行sql前将输入的java对象映射至sql中，输入参数映射就是jdbc编程中对preparedStatement设置参数。</p>
<p>7、Mapped Statement对sql执行输出结果进行定义，包括HashMap、基本类型、pojo，Executor通过Mapped Statement在执行sql后将输出结果映射至java对象中，输出结果映射过程相当于jdbc编程中对结果的解析处理过程。</p>
<h1 id="知识点">知识点</h1>
<h2 id="mysql自增主键返回">mysql自增主键返回</h2>
<pre><code>    &lt;!-- 添加用户 --&gt;
    &lt;insert id=&quot;insertUser&quot; parameterType=&quot;cn.itcast.mybatis.po.User&quot;&gt;
		&lt;!-- selectKey将主键返回，需要再返回 --&gt;
		&lt;selectKey keyProperty=&quot;id&quot; order=&quot;AFTER&quot; resultType=&quot;java.lang.Integer&quot;&gt;
			select LAST_INSERT_ID()
		&lt;/selectKey&gt;
	   insert into user(username,birthday,sex,address)values(#{username},#{birthday},#{sex},#{address})
	&lt;/insert&gt;	
</code></pre>
<p>说明：</p>
<ul>
<li>添加selectKey实现将主键返回</li>
<li>keyProperty：返回的主键存储在pojo中的哪个属性</li>
<li>order：selectKey的执行顺序，是相对与insert语句来说，由于mysql的自增原理执行完insert语句之后才将主键生成，所以这里selectKey的执行顺序为after</li>
<li>resultType：返回的主键是什么类型</li>
<li>LAST_INSERT_ID()：是mysql的函数，返回auto_increment自增列新记录id值</li>
<li>这里没有用到<code>useGeneratedKeys=&quot;true&quot; keyColumn=&quot;id&quot;</code>，有人说用到，参考：https://www.cnblogs.com/quan-coder/p/8728410.html</li>
</ul>
<p>后台通过<code>getId</code>获取自增键</p>
<pre><code>    public Integer insertUser(User user) {
        userDao.insertUser(user);
        return user.getId();
    }
</code></pre>
<h2 id="oracle使用序列生成主键">Oracle使用序列生成主键</h2>
<p>首先自定义一个序列且用于生成主键，selectKey使用如下：</p>
<pre><code>&lt;insert  id=&quot;insertUser&quot; parameterType=&quot;cn.itcast.mybatis.po.User&quot;&gt;
    &lt;selectKey resultType=&quot;java.lang.Integer&quot; order=&quot;BEFORE&quot; keyProperty=&quot;id&quot;&gt;
        SELECT 自定义序列.NEXTVAL FROM DUAL
    &lt;/selectKey&gt;
    insert into user(id,username,birthday,sex,address) 
    		 values(#{id},#{username},#{birthday},#{sex},#{address})
&lt;/insert&gt;
</code></pre>
<p>注意这里使用的order是“BEFORE”</p>
<p>如何返回主键？TODO&hellip;参考：https://blog.csdn.net/lcw785376995/article/details/82497048</p>
<h2 id="mysql使用-uuid实现主键">Mysql使用 uuid实现主键</h2>
<pre><code>&lt;insert  id=&quot;insertUser&quot; parameterType=&quot;cn.itcast.mybatis.po.User&quot;&gt;
    &lt;selectKey resultType=&quot;java.lang.String&quot; order=&quot;BEFORE&quot; keyProperty=&quot;id&quot;&gt;
        select uuid()
    &lt;/selectKey&gt;
    insert into user(id,username,birthday,sex,address)values(#{id},#{username},#{birthday},#{sex},#{address})
&lt;/insert&gt;
</code></pre>
<p>注意这里使用的order是“BEFORE”</p>
<h1 id="sqlmapconfigxml配置文件">SqlMapConfig.xml配置文件</h1>
<p>SqlMapConfig.xml中配置的内容和顺序如下：</p>
<pre><code>properties（属性）
settings（全局配置参数）
typeAliases（类型别名）
typeHandlers（类型处理器）
objectFactory（对象工厂）
plugins（插件）
environments（环境集合属性对象）
    environment（环境子属性对象）
        transactionManager（事务管理）
        dataSource（数据源）
mappers（映射器）
</code></pre>
<h2 id="properties属性">properties（属性）</h2>
<p>SqlMapConfig.xml可以引用java属性文件中的配置信息如下：</p>
<p>在classpath下定义db.properties文件，</p>
<pre><code>jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=mysql
</code></pre>
<p>SqlMapConfig.xml引用如下：</p>
<pre><code>&lt;properties resource=&quot;db.properties&quot;/&gt;
	&lt;environments default=&quot;development&quot;&gt;
		&lt;environment id=&quot;development&quot;&gt;
			&lt;transactionManager type=&quot;JDBC&quot;/&gt;
			&lt;dataSource type=&quot;POOLED&quot;&gt;
				&lt;property name=&quot;driver&quot; value=&quot;${jdbc.driver}&quot;/&gt;
				&lt;property name=&quot;url&quot; value=&quot;${jdbc.url}&quot;/&gt;
				&lt;property name=&quot;username&quot; value=&quot;${jdbc.username}&quot;/&gt;
				&lt;property name=&quot;password&quot; value=&quot;${jdbc.password}&quot;/&gt;
			&lt;/dataSource&gt;
		&lt;/environment&gt;
	&lt;/environments&gt;
</code></pre>
<p>注意： MyBatis 将按照下面的顺序来加载属性：</p>
<ul>
<li>在 properties 元素体内定义的属性首先被读取。</li>
<li>然后会读取properties 元素中resource或 url 加载的属性，它会覆盖已读取的同名属性。</li>
<li>最后读取parameterType传递的属性，它会覆盖已读取的同名属性。</li>
</ul>
<p>因此，通过parameterType传递的属性具有最高优先级，resource或 url 加载的属性次之，最低优先级的是 properties 元素体内定义的属性。</p>
<h2 id="settings配置">settings（配置）</h2>
<p>mybatis全局配置参数，全局参数将会影响mybatis的运行行为。</p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080421.png" alt="">
<img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080443.png" alt=""></p>
<p>可以去官网参考：http://www.mybatis.org/mybatis-3/zh/configuration.html</p>
<h2 id="typealiases类型别名">typeAliases（类型别名）</h2>
<p>mybatis支持别名：</p>
<table>
<thead>
<tr>
<th>别名</th>
<th>映射的类型</th>
</tr>
</thead>
<tbody>
<tr>
<td>_byte</td>
<td>byte</td>
</tr>
<tr>
<td>_long</td>
<td>long</td>
</tr>
<tr>
<td>_short</td>
<td>short</td>
</tr>
<tr>
<td>_int</td>
<td>int</td>
</tr>
<tr>
<td>_integer</td>
<td>int</td>
</tr>
<tr>
<td>_double</td>
<td>double</td>
</tr>
<tr>
<td>_float</td>
<td>float</td>
</tr>
<tr>
<td>_boolean</td>
<td>boolean</td>
</tr>
<tr>
<td>string</td>
<td>String</td>
</tr>
<tr>
<td>byte</td>
<td>Byte</td>
</tr>
<tr>
<td>long</td>
<td>Long</td>
</tr>
<tr>
<td>short</td>
<td>Short</td>
</tr>
<tr>
<td>int</td>
<td>Integer</td>
</tr>
<tr>
<td>integer</td>
<td>Integer</td>
</tr>
<tr>
<td>double</td>
<td>Double</td>
</tr>
<tr>
<td>float</td>
<td>Float</td>
</tr>
<tr>
<td>boolean</td>
<td>Boolean</td>
</tr>
<tr>
<td>date</td>
<td>Date</td>
</tr>
<tr>
<td>decimal</td>
<td>BigDecimal</td>
</tr>
<tr>
<td>bigdecimal</td>
<td>BigDecimal</td>
</tr>
</tbody>
</table>
<p>自定义别名：</p>
<p>在SqlMapConfig.xml中配置：</p>
<pre><code>&lt;typeAliases&gt;
	&lt;!-- 单个别名定义 --&gt;
	&lt;typeAlias alias=&quot;user&quot; type=&quot;cn.itcast.mybatis.po.User&quot;/&gt;
	&lt;!-- 批量别名定义，扫描整个包下的类 --&gt;
	&lt;package name=&quot;domain.blog&quot;/&gt;
	&lt;package name=&quot;其它包&quot;/&gt;
&lt;/typeAliases&gt;
</code></pre>
<p>每一个在包 domain.blog 中的 Java Bean，在没有注解的情况下，会使用 Bean 的首字母小写的非限定类名来作为它的别名。 比如 domain.blog.Author 的别名为 author；若有注解，则别名为其注解值。见下面的例子：</p>
<pre><code>@Alias(&quot;author&quot;)
public class Author {
    ...
}
</code></pre>
<h2 id="typehandlers类型处理器">typeHandlers（类型处理器）</h2>
<p>类型处理器用于java类型和jdbc类型映射，如下：</p>
<pre><code>&lt;select id=&quot;findUserById&quot; parameterType=&quot;int&quot; resultType=&quot;user&quot;&gt;
		select * from user where id = #{id}
&lt;/select&gt;
</code></pre>
<p>mybatis自带的类型处理器基本上满足日常需求，不需要单独定义。</p>
<p>mybatis支持类型处理器：</p>
<table>
<thead>
<tr>
<th>类型处理器</th>
<th>Java类型</th>
<th>JDBC类型</th>
</tr>
</thead>
<tbody>
<tr>
<td>BooleanTypeHandler</td>
<td>Boolean，boolean</td>
<td>任何兼容的布尔值</td>
</tr>
<tr>
<td>ByteTypeHandler</td>
<td>Byte，byte</td>
<td>任何兼容的数字或字节类型</td>
</tr>
<tr>
<td>ShortTypeHandler</td>
<td>Short，short</td>
<td>任何兼容的数字或短整型</td>
</tr>
<tr>
<td>IntegerTypeHandler</td>
<td>Integer，int</td>
<td>任何兼容的数字和整型</td>
</tr>
<tr>
<td>LongTypeHandler</td>
<td>Long，long</td>
<td>任何兼容的数字或长整型</td>
</tr>
<tr>
<td>FloatTypeHandler</td>
<td>Float，float</td>
<td>任何兼容的数字或单精度浮点型</td>
</tr>
<tr>
<td>DoubleTypeHandler</td>
<td>Double，double</td>
<td>任何兼容的数字或双精度浮点型</td>
</tr>
<tr>
<td>BigDecimalTypeHandler</td>
<td>BigDecimal</td>
<td>任何兼容的数字或十进制小数类型</td>
</tr>
<tr>
<td>StringTypeHandler</td>
<td>String</td>
<td>CHAR和VARCHAR类型</td>
</tr>
<tr>
<td>ClobTypeHandler</td>
<td>String</td>
<td>CLOB和LONGVARCHAR类型</td>
</tr>
<tr>
<td>NStringTypeHandler</td>
<td>String</td>
<td>NVARCHAR和NCHAR类型</td>
</tr>
<tr>
<td>NClobTypeHandler</td>
<td>String</td>
<td>NCLOB类型</td>
</tr>
<tr>
<td>ByteArrayTypeHandler</td>
<td>byte[]</td>
<td>任何兼容的字节流类型</td>
</tr>
<tr>
<td>BlobTypeHandler</td>
<td>byte[]</td>
<td>BLOB和LONGVARBINARY类型</td>
</tr>
<tr>
<td>DateTypeHandler</td>
<td>Date（java.util）</td>
<td>TIMESTAMP类型</td>
</tr>
<tr>
<td>DateOnlyTypeHandler</td>
<td>Date（java.util）</td>
<td>DATE类型</td>
</tr>
<tr>
<td>TimeOnlyTypeHandler</td>
<td>Date（java.util）</td>
<td>TIME类型</td>
</tr>
<tr>
<td>SqlTimestampTypeHandler</td>
<td>Timestamp（java.sql）</td>
<td>TIMESTAMP类型</td>
</tr>
<tr>
<td>SqlDateTypeHandler</td>
<td>Date（java.sql）</td>
<td>DATE类型</td>
</tr>
<tr>
<td>SqlTimeTypeHandler</td>
<td>Time（java.sql）</td>
<td>TIME类型</td>
</tr>
<tr>
<td>ObjectTypeHandler</td>
<td>任意</td>
<td>其他或未指定类型</td>
</tr>
<tr>
<td>EnumTypeHandler</td>
<td>Enumeration类型</td>
<td>VARCHAR-任何兼容的字符串类型，作为代码存储（而不是索引）。</td>
</tr>
</tbody>
</table>
<h2 id="mappers映射器">mappers（映射器）</h2>
<p>Mapper配置的几种方法：</p>
<ul>
<li><code>&lt;mapper resource=&quot; &quot; /&gt;</code>，相对于类路径的资源，如：<code>&lt;mapper resource=&quot;sqlmap/User.xml&quot; /&gt;</code></li>
<li><code>&lt;mapper url=&quot; &quot; /&gt;</code>，使用完全限定路径，如：<code>&lt;mapper url=&quot;file:///D:\workspace_spingmvc\mybatis_01\config\sqlmap\User.xml&quot; /&gt;</code></li>
<li><code>&lt;mapper class=&quot; &quot; /&gt;</code>，使用mapper接口类路径，如：<code>&lt;mapper class=&quot;cn.itcast.mybatis.mapper.UserMapper&quot;/&gt;</code>，注意：此种方法要求mapper接口名称和mapper映射文件名称相同，且放在同一个目录中</li>
<li><code>&lt;package name=&quot;&quot;/&gt;</code>，注册指定包下的所有mapper接口，如：<code>&lt;package name=&quot;cn.itcast.mybatis.mapper&quot;/&gt;</code>，注意：此种方法要求mapper接口名称和mapper映射文件名称相同，且放在同一个目录中</li>
</ul>
<h1 id="mapperxml映射文件">Mapper.xml映射文件</h1>
<p>Mapper.xml映射文件中定义了操作数据库的sql，每个sql是一个statement，映射文件是mybatis的核心。</p>
<h2 id="parametertype输入类型">parameterType(输入类型)</h2>
<h3 id="与">#{}与$</h3>
<p>#{}实现的是向prepareStatement中的预处理语句中设置参数值，sql语句中#{}表示一个占位符，即?</p>
<p>使用占位符#{}可以有效防止sql注入</p>
<p>${}是进行字符串的接连</p>
<h3 id="传递pojo对象">传递pojo对象</h3>
<pre><code>	&lt;select id=&quot;findUserByUser&quot; parameterType=&quot;user&quot; resultType=&quot;user&quot;&gt;
	   select * from user where id=#{id} and username like '%${username}%'
	&lt;/select&gt;
</code></pre>
<h3 id="传递pojo包装对象">传递pojo包装对象</h3>
<p>定义包装对象</p>
<pre><code>public class QueryVo {
	
	private User user;
	
	//自定义用户扩展类
	private UserCustom userCustom;
</code></pre>
<p>mapper.xml映射文件</p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080541.png" alt=""></p>
<p>说明：mybatis底层通过ognl从pojo中获取属性值：#{user.username}，user即是传入的包装对象的属性。queryVo是别名，即上边定义的包装对象类型</p>
<h3 id="传递hashmap">传递hashmap</h3>
<pre><code>    &lt;!-- 传递hashmap综合查询用户信息 --&gt;
	&lt;select id=&quot;findUserByHashmap&quot; parameterType=&quot;hashmap&quot; resultType=&quot;user&quot;&gt;
	   select * from user where id=#{id} and username like '%${username}%'
	&lt;/select&gt;
</code></pre>
<p>测试：</p>
<pre><code>Public void testFindUserByHashmap()throws Exception{
		//获取session
		SqlSession session = sqlSessionFactory.openSession();
		//获限mapper接口实例
		UserMapper userMapper = session.getMapper(UserMapper.class);
		//构造查询条件Hashmap对象
		HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
		map.put(&quot;id&quot;, 1);
		map.put(&quot;username&quot;, &quot;管理员&quot;);
		
		//传递Hashmap对象查询用户列表
		List&lt;User&gt;list = userMapper.findUserByHashmap(map);
		//关闭session
		session.close();
	}
</code></pre>
<h2 id="resulttype输出类型">resultType(输出类型)</h2>
<h3 id="输出pojo对象">输出pojo对象</h3>
<pre><code>	&lt;!-- 根据id查询用户信息 --&gt;
	&lt;select id=&quot;findUserById&quot; parameterType=&quot;int&quot; resultType=&quot;user&quot;&gt;
		select * from user where id = #{id}
	&lt;/select&gt;
</code></pre>
<pre><code>public User findUserById(int id) throws Exception;
</code></pre>
<h3 id="输出pojo列表">输出pojo列表</h3>
<pre><code>    &lt;!-- 根据名称模糊查询用户信息 --&gt;
	&lt;select id=&quot;findUserByUsername&quot; parameterType=&quot;string&quot; resultType=&quot;user&quot;&gt;
	   select * from user where username like '%${value}%'
	&lt;/select&gt;
</code></pre>
<pre><code>public List&lt;User&gt; findUserByUsername(String username) throws Exception;
</code></pre>
<h3 id="输出hashmap">输出hashmap</h3>
<p>输出pojo对象可以改用hashmap输出类型，将输出的字段名称作为map的key，value为字段值。</p>
<h2 id="resultmap输出类型">resultMap（输出类型）</h2>
<p>resultType可以指定pojo将查询结果映射为pojo，但需要pojo的属性名和sql查询的列名一致方可映射成功。</p>
<p>如果sql查询字段名和pojo的属性名不一致，可以通过resultMap将字段名和属性名作一个对应关系 ，resultMap实质上还需要将查询结果映射到pojo对象中。</p>
<p>resultMap可以实现将查询结果映射为复杂类型的pojo，比如在查询结果映射对象中包括pojo和list实现一对一查询和一对多查询。</p>
<p>1、Mapper定义</p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080615.png" alt=""></p>
<p>使用resultMap指定上边定义的personmap。</p>
<p>2、定义resultMap</p>
<p>由于上边的mapper.xml中sql查询列和Users.java类属性不一致，需要定义resultMap：userListResultMap将sql查询列和Users.java类属性对应起来</p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080704.png" alt=""></p>
<ul>
<li><!-- raw HTML omitted -->：此属性表示查询结果集的唯一标识，非常重要。如果是多个字段为复合唯一约束则定义多个<!-- raw HTML omitted -->。</li>
<li>Property：表示person类的属性。</li>
<li>Column：表示sql查询出来的字段名。</li>
<li>Column和property放在一块儿表示将sql查询出来的字段映射到指定的pojo类属性上。</li>
<li><!-- raw HTML omitted -->：普通结果，即pojo的属性。</li>
</ul>
<p>3、Mapper接口定义</p>
<pre><code>public List&lt;User&gt; findUserListResultMap() throws Exception;
</code></pre>
<h2 id="动态sql重点">动态sql(重点)</h2>
<p>通过mybatis提供的各种标签方法实现动态拼接sql。</p>
<h3 id="if">If</h3>
<pre><code>	&lt;select id=&quot;findUserList&quot; parameterType=&quot;user&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		where 1=1 
		&lt;if test=&quot;id!=null and id!=''&quot;&gt;
		and id=#{id}
		&lt;/if&gt;
		&lt;if test=&quot;username!=null and username!=''&quot;&gt;
		and username like '%${username}%'
		&lt;/if&gt;
	&lt;/select&gt;
</code></pre>
<h3 id="where">Where</h3>
<p>上边的sql也可以改为：</p>
<pre><code>    &lt;select id=&quot;findUserList&quot; parameterType=&quot;user&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		&lt;if test=&quot;id!=null and id!=''&quot;&gt;
		and id=#{id}
		&lt;/if&gt;
		&lt;if test=&quot;username!=null and username!=''&quot;&gt;
		and username like '%${username}%'
		&lt;/if&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<p><!-- raw HTML omitted -->可以自动处理第一个and</p>
<h3 id="foreach">foreach</h3>
<p>向sql传递数组或List，mybatis使用foreach解析</p>
<h4 id="通过pojo传递list">通过pojo传递list</h4>
<ul>
<li>
<p>需求</p>
<p>传入多个id查询用户信息，用下边两个sql实现：</p>
</li>
</ul>
<pre><code>    SELECT * FROM USERS WHERE username LIKE '%张%' AND (id =10 OR id =89 OR id=16)
    SELECT * FROM USERS WHERE username LIKE '%张%' and id IN (10,89,16)
</code></pre>
<ul>
<li>
<p>在pojo中定义list属性ids存储多个用户id，并添加getter/setter方法</p>
<p><img src="https://gitee.com/rulerLwx/PicGo/raw/master/img/20200708080728.png" alt=""></p>
</li>
<li>
<p>mapper.xml</p>
</li>
</ul>
<pre><code>    &lt;if test=&quot;ids!=null and ids.size &gt; 0&quot;&gt;
    	&lt;foreach collection=&quot;ids&quot; open=&quot; and id in(&quot; close=&quot;)&quot; item=&quot;id&quot; separator=&quot;,&quot; &gt;
    		#{id}
    	&lt;/foreach&gt;
    &lt;/if&gt;
</code></pre>
<ul>
<li>测试</li>
</ul>
<pre><code>    List&lt;Integer&gt; ids = new ArrayList&lt;Integer&gt;();
    ids.add(1);//查询id为1的用户
    ids.add(10); //查询id为10的用户
    queryVo.setIds(ids);
    List&lt;User&gt; list = userMapper.findUserList(queryVo);
</code></pre>
<h4 id="传递单个list">传递单个List</h4>
<p>传递List类型在编写mapper.xml没有区别，唯一不同的是只有一个List参数时它的参数名为list。</p>
<ul>
<li>Mapper.xml</li>
</ul>
<pre><code>    &lt;select id=&quot;selectUserByList&quot; parameterType=&quot;java.util.List&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		&lt;!-- 传递List，List中是pojo --&gt;
		&lt;if test=&quot;list!=null&quot;&gt;
		&lt;foreach collection=&quot;list&quot; item=&quot;item&quot; open=&quot;and id in(&quot;separator=&quot;,&quot;close=&quot;)&quot;&gt;
		    #{item.id} 
		&lt;/foreach&gt;
		&lt;/if&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<ul>
<li>Mapper接口</li>
</ul>
<pre><code>    public List&lt;User&gt; selectUserByList(List userlist) throws Exception;
</code></pre>
<ul>
<li>测试</li>
</ul>
<pre><code>    Public void testselectUserByList()throws Exception{
    		//获取session
    		SqlSession session = sqlSessionFactory.openSession();
    		//获限mapper接口实例
    		UserMapper userMapper = session.getMapper(UserMapper.class);
    		//构造查询条件List
    		List&lt;User&gt; userlist = new ArrayList&lt;User&gt;();
    		User user = new User();
    		user.setId(1);
    		userlist.add(user);
    		user = new User();
    		user.setId(2);
    		userlist.add(user); 
    		//传递userlist列表查询用户列表
    		List&lt;User&gt;list = userMapper.selectUserByList(userlist);
    		//关闭session
    		session.close();
    }
</code></pre>
<h4 id="传递单个数组数组中是pojo">传递单个数组（数组中是pojo）</h4>
<ul>
<li>Mapper.xml</li>
</ul>
<pre><code>	&lt;select id=&quot;selectUserByArray&quot; parameterType=&quot;Object[]&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		&lt;!-- 传递数组 --&gt;
		&lt;if test=&quot;array!=null&quot;&gt;
		&lt;foreach collection=&quot;array&quot; index=&quot;index&quot; item=&quot;item&quot; open=&quot;and id in(&quot;separator=&quot;,&quot;close=&quot;)&quot;&gt;
		    #{item.id} 
		&lt;/foreach&gt;
		&lt;/if&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<p>sql只接收一个数组参数，这时sql解析参数的名称mybatis固定为array，</p>
<p>如果数组是通过一个pojo传递到sql则参数的名称为pojo中的属性名。</p>
<pre><code>- index：为数组的下标。
- item：为数组每个元素的名称，名称随意定义
- open：循环开始
- close：循环结束
- separator：中间分隔输出
</code></pre>
<ul>
<li>Mapper接口</li>
</ul>
<pre><code>public List&lt;User&gt; selectUserByArray(Object[] userlist) throws Exception;
</code></pre>
<ul>
<li>测试</li>
</ul>
<pre><code>    Public void testselectUserByArray()throws Exception{
		//获取session
		SqlSession session = sqlSessionFactory.openSession();
		//获限mapper接口实例
		UserMapper userMapper = session.getMapper(UserMapper.class);
		//构造查询条件List
		Object[] userlist = new Object[2];
		User user = new User();
		user.setId(1);
		userlist[0]=user;
		user = new User();
		user.setId(2);
		userlist[1]=user;
		//传递user对象查询用户列表
		List&lt;User&gt;list = userMapper.selectUserByArray(userlist);
		//关闭session
		session.close();
	}
</code></pre>
<h4 id="传递单个数组数组中是字符串类型">传递单个数组（数组中是字符串类型）</h4>
<ul>
<li>Mapper.xml</li>
</ul>
<pre><code>	&lt;select id=&quot;selectUserByArray&quot; parameterType=&quot;Object[]&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		&lt;!-- 传递数组 --&gt;
		&lt;if test=&quot;array!=null&quot;&gt;
		&lt;foreach collection=&quot;array&quot;index=&quot;index&quot;item=&quot;item&quot;open=&quot;and id in(&quot;separator=&quot;,&quot;close=&quot;)&quot;&gt;
		    #{item} 
		&lt;/foreach&gt;
		&lt;/if&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<p>如果数组中是简单类型则写为#{item}，不用再通过ognl获取对象属性值了。</p>
<ul>
<li>Mapper接口</li>
</ul>
<pre><code>    public List&lt;User&gt; selectUserByArray(Object[] userlist) throws Exception;
</code></pre>
<ul>
<li>测试：</li>
</ul>
<pre><code>    Public void testselectUserByArray()throws Exception{
		//获取session
		SqlSession session = sqlSessionFactory.openSession();
		//获限mapper接口实例
		UserMapper userMapper = session.getMapper(UserMapper.class);
		//构造查询条件List
		Object[] userlist = new Object[2];
		userlist[0]=”1”;
		userlist[1]=”2”;
		//传递user对象查询用户列表
		List&lt;User&gt;list = userMapper.selectUserByArray(userlist);
		//关闭session
		session.close();
	}
</code></pre>
<h3 id="sql片段">Sql片段</h3>
<p>Sql中可将重复的sql提取出来，使用时用include引用即可，最终达到sql重用的目的，如下：</p>
<pre><code>	&lt;select id=&quot;findUserList&quot; parameterType=&quot;user&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		&lt;if test=&quot;id!=null and id!=''&quot;&gt;
		and id=#{id}
		&lt;/if&gt;
		&lt;if test=&quot;username!=null and username!=''&quot;&gt;
		and username like '%${username}%'
		&lt;/if&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<p>将where条件抽取出来：</p>
<pre><code>    &lt;sql id=&quot;query_user_where&quot;&gt;
    	&lt;if test=&quot;id!=null and id!=''&quot;&gt;
    		and id=#{id}
    	&lt;/if&gt;
    	&lt;if test=&quot;username!=null and username!=''&quot;&gt;
    		and username like '%${username}%'
    	&lt;/if&gt;
    &lt;/sql&gt;
</code></pre>
<p>使用include引用：</p>
<pre><code>    &lt;select id=&quot;findUserList&quot; parameterType=&quot;user&quot; resultType=&quot;user&quot;&gt;
		select * from user 
		&lt;where&gt;
		    &lt;include refid=&quot;query_user_where&quot;/&gt;
		&lt;/where&gt;
	&lt;/select&gt;
</code></pre>
<p>注意：如果引用其它mapper.xml的sql片段，则在引用时需要加上namespace，如下：</p>
<pre><code>&lt;include refid=&quot;namespace.sql片段”/&gt;
</code></pre>

    </div>
    <div class="article-footer">
<blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    <li class="post-copyright-link hidden-xs">
      <strong>Permalink: </strong>
      <a href="https://rulerLwx.gitee.io/2020/07/java-framework-mybatis-1/" title="Java-framework-MyBatis-1" target="_blank" rel="external">https://rulerLwx.gitee.io/2020/07/java-framework-mybatis-1/</a>
    </li>
    <li class="post-copyright-license">
      <strong>License：</strong><a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN</a>
    </li>
  </ul>
</blockquote>

<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://gitee.com/rulerLwx" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="https://rulerLwx.gitee.io/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://gitee.com/rulerLwx" target="_blank"><span class="text-dark">rulerLwx</span><small class="ml-1x">thinking...</small></a></h3>
        <div>Good Good Study, Day Day Up~</div>
      </div>
    </figure>
  </div>
</div>
    </div>
  </article>
<section id="comments">
    <div id="vcomments"></div>
</section>

</div><nav class="bar bar-footer clearfix" data-stick-bottom>
    <div class="bar-inner">
        <ul class="pager pull-left">
            <li class="prev">
                <a href="https://rulerLwx.gitee.io/2020/07/java-framework-mybatis-2-%E5%85%B3%E8%81%94%E6%9F%A5%E8%AF%A2/" title="Java-framework-MyBatis-2-关联查询"><i
                        class="icon icon-angle-left"
                        aria-hidden="true"></i><span>&nbsp;&nbsp;Older</span></a>
            </li>
            <li class="next">
                <a href="https://rulerLwx.gitee.io/2020/07/java-framework-json/"
                    title="Java-framework-JSON"><span>Newer&nbsp;&nbsp;</span><i
                        class="icon icon-angle-right" aria-hidden="true"></i></a>
            </li>
            
            <li class="toggle-toc">
                <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false"
                    title="Catalogue" role="button">
                    <span>[&nbsp;</span><span>Catalogue</span>
                    <i class="text-collapsed icon icon-anchor"></i>
                    <i class="text-in icon icon-close"></i>
                    <span>]</span>
                </a>
            </li>
        </ul>
        <div class="bar-right">
            <div class="share-component" data-sites="weibo,qq,wechat"
                data-mobile-sites="weibo,qq,qzone"></div>
        </div>
    </div>
</nav>

</main><footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
<ul class="social-links">
    <li><a href="https://gitee.com/rulerLwx" target="_blank" title="gitee" data-toggle=tooltip data-placement=top >
            <i class="icon icon-gitee"></i></a></li>
    <li><a href="https://github.com/wolf-lea" target="_blank" title="github" data-toggle=tooltip data-placement=top >
            <i class="icon icon-github"></i></a></li>
</ul>
  <div class="copyright">
    &copy;2020  -
    2020
    <div class="publishby">
        Theme by <a href="https://github.com/xiaoheiAh" target="_blank"> xiaoheiAh </a>base on<a href="https://github.com/xiaoheiAh/hugo-theme-pure" target="_blank"> pure</a>.
    </div>
  </div>
</footer>

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_SVG"></script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
            showMathMenu: false, //disables context menu
            tex2jax: {
            inlineMath: [ ['$','$'], ['\\(','\\)'] ]
           }
    });
</script>


<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/python.min.js" defer></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/javascript.min.js" defer></script><script>
    hljs.configure({
        tabReplace: '    ', 
        classPrefix: ''     
        
    })
    hljs.initHighlightingOnLoad();
</script>
<script src="https://rulerLwx.gitee.io/js/application.min.bdeb64b910570b6c41badc6a05b7afb0c8ad9efd8525de3c7257d59e786326a3.js"></script>
<script src="https://rulerLwx.gitee.io/js/plugin.min.51ff8c7317566f82259170fa36e09c4493adc9b9378b427a01ad3f017ebac7dd.js"></script>

<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: 'Posts',
                PAGES: 'Pages',
                CATEGORIES: 'Categories',
                TAGS: 'Tags',
                UNTITLED: '(Untitled)',
            },
            ROOT_URL: 'https:\/\/rulerLwx.gitee.io',
            CONTENT_URL: 'https:\/\/rulerLwx.gitee.io\/searchindex.json ',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script type="text/javascript" src="https://rulerLwx.gitee.io/js/insight.min.a343cd9a5a7698336b28ef3a7c16a3a1b1d2d5fb17dc8ed04022bbe08cc5459073a15bdafa3a8a58cdd56080784bdd69fa70b1ae8597565c799c57ed00f0e120.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script>
<script>
    tocbot.init({
        
        tocSelector: '.js-toc',
        
        contentSelector: '.js-toc-content',
        
        headingSelector: 'h1, h2, h3',
        
        hasInnerContainers: true,
    });
</script>

<script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine"></script>
<script type="text/javascript">
    var GUEST = ['nick', 'mail', 'link'];
    var meta = 'nick,mail';
    meta = meta.split(',').filter(function (item) {
        return GUEST.indexOf(item) > -1;
    });
    new Valine({
        el: '#vcomments',
        verify: null ,
        notify: null ,
        appId: 'IyAB0PSPRazTPDxitO1ddQ7O-gzGzoHsz',
        appKey: '5rBJTq4KidYF33eXwvRVhtEH',
        placeholder: 'enjoy~',
        avatar: 'mm',
        meta: meta,
        pageSize: '10' || 10,
        visitor: false 
});
</script>

  </body>
</html>
